Strict
#Rem
Header: AGFX Framework. 
#End
Import mojo
Import agfx

#Rem
summary: AGFX TFramework
#End
Class TFramework Extends App

	Public

	#Rem
	summary: enable draw debug information
	#End	
	Field debug_On:Bool 			= False
	
	#Rem
	summary: enable draw FPS info
	#End	
	Field fps_On:Bool 				= False
	
	#Rem
	summary: enable visual framerate/FPS info
	#End	
	Field graph_On:Bool 			= False

	#Rem
	summary: assigned current screen component
	#End	
	Field currentScreen:TScreen
	
	#Rem
	summary: assigned next screen component
	is used as current after fade effect
	#End	
	Field nextScreen:TScreen
	
	#Rem
	summary: exist screen
	#End	
	Field exitScreen:TScreenExit = New TScreenExit()
	
	#Rem
	summary: fade screen FX used when current screen switched to next
	#End	
	Field fadeScreen:TScreenFade = New TScreenFade()
	
	#Rem
	summary: is called when APP is created	
	#End	
	Method OnCreate:Int()
		
		' set screen size from DEVICE size
		DISPLAY.SetVirtualSize()
				
		' Set the Random seed
		Seed = RealMillisecs()
		
		SetUpdateRate(TARGET_FPS)
			
		Return 0
	End
	
	#Rem
	summary: is called in App Render loop
	#End	
	Method OnRender:Int()
		
		If DISPLAY.IsVirtualScaleUsed() Then DISPLAY.UpdateVirtualDisplay()
		
		Self.currentScreen.Render()
		
		If Self.fadeScreen.active Then Self.fadeScreen.Render()
		
		SPRITES.Render()
		
		Self.currentScreen.ExtraRender()
		
		If Self.debug_On
			Self.DrawDebug()
		End
		
		If Self.fps_On		
			Self.DrawFPS()
		End
	
		If Self.graph_On		
			FPSGRAPH.Render()
		End
		'CONSOLE.Draw()
		
		Return 0
	End
	#Rem
	summary: is called in App Update loop
	#End	
	Method OnUpdate:Int()
	
		FPSGRAPH.Update()
	
		UpdateAppTime()
		
		MOUSE.Update()		

		If Self.fadeScreen.active Then Self.fadeScreen.Update()
		Self.currentScreen.Update()
		
		SPRITES.Update()
		
		Return 0
	End
	#Rem
	summary: is called on app resume
	#End	
	Method OnResume:Int()
		Return 0
	End
	#Rem
	summary: is called on app suspend
	#End	
	Method OnSuspend:Int()
		Return 0
	End
	#Rem
	summary: is called on app pause
	#End	
	Method OnPause:Int()
		Return 0
	End
	#Rem
	summary: is called on app loading resources
	don't work correct in monkey
	#End	
	Method OnLoading:Int()
		Return 0
	End
	
	Private
	

	Method DrawDebug:Void()
		
		Local line:Int=0

		SetBlend(1)
		SetColor 0, 0, 0
		DrawRect 0, 0, 200, 100
		SetColor 96, 96, 96
		DrawFPS()
		DrawText "Screen         = "+Self.currentScreen.name,0, line+10
		DrawText "Delta          = "+FormatNumber(AppSpeed(), 2) , 0, line+20
		DrawText "Device Width   = "+DISPLAY.DEVICE_WIDTH,0, line+30
		DrawText "Device Height  = "+DISPLAY.DEVICE_HEIGHT,0, line+40
		DrawText "Screen Width   = "+DISPLAY.VSCREEN_WIDTH,0, line+50
		DrawText "Screen Height  = "+DISPLAY.VSCREEN_HEIGHT,0, line+60
		DrawText "VMouseX        = "+MOUSE.x,0, line+70
		DrawText "VMouseY        = "+MOUSE.y,0, line+80
		DrawText "MouseX         = "+MouseX(),0, line+90
		DrawText "MouseY         = "+MouseY(),0, line+100
		DrawText "Zoom           = "+DISPLAY.GetZoom(),0, line+110
		DrawText "Size Ration    = "+DISPLAY.GetRatio(),0, line+120
		SetBlend(0)
	End
	
	Method DrawFPS:Void()
		SetBlend(1)
		DrawText FPS(), 0, 0
		SetBlend(0)
	End
	
	Method DrawFPS:Void(x:Int,y:Int)
		SetBlend(1)
		DrawText FPS(), x, y
		SetBlend(0)
	End
End






